﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="buildorder.aspx.cs" Inherits="TogoHome_FoodDetailbuildorder" %>

<%@ Register Src="~/Banner.ascx" TagPrefix="top" TagName="banner" %>
<%@ Register Src="~/header.ascx" TagName="banner" TagPrefix="uc1" %>
<%@ Register Src="~/Foot.ascx" TagPrefix="foot" TagName="foot" %>
<%@ Register Src="~/shop/Left.ascx" TagName="LeftBanner" TagPrefix="uc2" %>


<%@ Register TagPrefix="epc" Namespace="Hangjing.Control" Assembly="Hangjing.Control" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>门店下单 - <%= WebUtility.GetWebName() %></title>
    <link href="/user/css/userinfo.css" rel="stylesheet" type="text/css" />
    <link href="/css/common.css" rel="stylesheet" type="text/css" />
    <link href="/css/style.css" rel="stylesheet" type="text/css" />
    <link href="/user/css/common.css?v=2016063013" rel="stylesheet" type="text/css" />
    <link href="../css/sweetalert.css" rel="stylesheet" />

    <script src="../JavaScript/jquery-1.3.2.js" type="text/javascript"></script>

    <script src="../JavaScript/ShowDivDialog.js" type="text/javascript"></script>

    <script src="../javascript/DatePicker/WdatePicker.js" type="text/javascript"></script>


    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=fMnzyhYs0D1cBEl5iGMQ0Dlg"></script>

    <script src="../javascript/sweetalert.min.js"></script>


    <script src="../javascript/eventwrapper.min.js" type="text/javascript"></script>

    <script src="../javascript/mymap.js" type="text/javascript"></script>
    <script src="../javascript/sendfee.js"></script>
    <script src="../javascript/spin.min.js"></script>




    <style type="text/css">
        #cblweekday {
            float: left;
        }

        .mynotice {
            background-color: #F1FAFE;
            border: 1px solid #B1DFF3;
            padding: 3px;
            color: #0863C0;
            _padding-top: 6px;
            margin-left: 3px;
            display: inline;
        }

        .hidden {
            display: none;
        }

        .quick_note_control span {
            border: 1px solid #CCCCCC;
            cursor: pointer;
            font-size: 12px;
            margin-right: 3px;
            padding: 4px 8px 3px 8px;
            display: inline-block;
            white-space: nowrap;
            margin-bottom: 5px;
            line-height: 20px;
        }

        .quick_note_control {
            width: 500px;
        }

            .quick_note_control .selectedbg {
                background-color: #f1fafc;
            }

            .quick_note_control .cull {
                background: none repeat scroll 0 0 #FFF0DF;
                color: #ff8400;
            }
    </style>

    <script type="text/javascript">


        function showmap() {
            var tbaddress = $("#tbaddress").val() + "";
            if (tbaddress == "") {
                alert("请输入您的地址");
                return;
            }
            setPlace();
        }

        var ac;
        var myValue;
        var isInitMap = false;

        $(document).ready(function () {
         

            var cityname = $("#hfcityname").val();
            //建立一个自动完成的对象
            ac = new BMap.Autocomplete(
            {
                "input": "tbaddress",
                "location": map
            });

            ac.addEventListener("onconfirm", function (e) {    //鼠标点击下拉列表后的事件
                var _value = e.item.value;
                myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
                setPlace();
               
            });

        })

        function setLatLng(point) {
            document.getElementById("hidLat").value = point.lat;
            document.getElementById("hidLng").value = point.lng;
            return true;
        }


        function onSearchComplete(result) {
          
           

            for (i = 0; i < result.getCurrentNumPois() && i < 1; i++) {
                var poi = result.getPoi(i);
                setLatLng(poi.point);
                map.panTo(poi.point);
            }

        }

      



        function setPlace() {
            var address = $("#tbaddress").val();
            var cityname = $("#hfcityname").val();

            var patrn = /\d+号/; //有具体的门牌号是要用地址解析，否则使用智能搜索
            if (patrn.test(address)) {
                myGeo.getPoint(address, function (point) {
                    if (point) {
                        setLatLng(point);

                        searchSuccess();
                    }
                    else {
                        searchFail();
                    }
                }, cityname);

            }
            else {

                var local = new BMap.LocalSearch(cityname, {
                    map: map,
                    autoViewport: true,
                    selectFirstResult: true,
                    onSearchComplete: function (result) {
                        if (result != null && result.getPoi(0) != null) {
                            initpoint = result.getPoi(0).point;
                            setLatLng(initpoint);
                            searchSuccess();
                        }
                        else {
                            searchFail();
                        }
                    }

                });


                local.search(address);
            }
        }


        function searchSuccess() {
            $("#tbaddress").css({ "border-color": "#707070 #CECECE #CECECE #707070" });
            $("#tbsearchaddress").val("搜索成功");
            $("#tbsearchaddress").css({ "color": "#333" }).val("搜索成功");
        }

        function searchFail() {
            $("#tbaddress").css({ "border-color": "red" });
            $("#tbsearchaddress").css({ "color": "red" }).val("搜索失败");

            alert("未找到相应地址,点击确定在直接在地图上标注定位");

            $("#hfaddress").val($("#tbaddress").val());

            $("#mapdiv").show();
            if (!isInitMap) {
                initialize();
            }
          

        }

        //点击获取用户地址
        function getmyaddress() {
            var tel = $("#tbtel").val();
            if (tel == "") {
                alert("请输入电话");
                return;
            }
            window.location = "buildorder.aspx?tel=" + tel + "&start=1";
            return false;
        }




    </script>




</head>
<body>
    <form id="form1" runat="server">
        <asp:HiddenField runat="server" ID="hidLat" />
        <asp:HiddenField runat="server" ID="hidLng" />
        <asp:HiddenField runat="server" ID="hidlocalflag" />

        <asp:HiddenField runat="server" ID="hftid" />
         <asp:HiddenField runat="server" ID="hfmymoney" Value="0" />
        <asp:HiddenField runat="server" ID="add_dataid" Value="0" />
         <asp:HiddenField runat="server" ID="hfaddress" Value="" />


        <asp:HiddenField runat="server" ID="hfcityname" Value="全国" />

        <top:banner ID="Banner1" runat="server" />
        <uc1:banner ID="Banner2" runat="server" />
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>

                <div class="shop_containner clearfix">

                    <uc2:LeftBanner runat="server" ID="Left" />

                    <div class="shop_main">
                        <div class="main-content">


                            <h1 class="topbg">门店下单</h1>



                            <div class="usermima">
                                <ul>
                                   
                                    <li><span class="left_span">电话<font color="red">*</font>：</span>
                                        <asp:TextBox runat="server" ID="tbtel" CanBeNull="必填" Width="160px" reg="\S" tip="请输入电话"  class="required-entry input_on FormBase" onkeydown="return enterIn(event,getmyaddress)"></asp:TextBox>
                                        <span id="lbtelmsg" runat="server" style="color: red;"></span>
                                        <input type="button" class="subBtn" onclick="getmyaddress()" id="btgetaddress" value="获取地址" />
                                    </li>
                                     <li><span class="left_span">姓名<font color="red"></font>：</span>
                                        <epc:TextBox runat="server" ID="tbuname"  Width="160px" class="required-entry input_on"></epc:TextBox>
                                        <span></span>
                                    </li>

                                    <li>
                                        <div class=" noseeitem" style="padding-left: 65px;">
                                            <ul class="myadd_ul">
                                                <asp:Repeater runat="server" ID="rptaddress">
                                                    <ItemTemplate>
                                                        <li>
                                                            <input type="radio" id="addrlist_<%# Eval("dataid") %>" name="addressradio1" <%#(Container.ItemIndex+1).ToString() == "1" ? "checked" : "" %>
                                                                class="radio1 <%#(Container.ItemIndex+1).ToString() == "1" ? "first_addr" : "" %>"
                                                                onclick="setaddress(this);" value="<%# Eval("Receiver") %>^<%# Eval("Address")%>^<%# Eval("lat") %>^<%# Eval("lng")%>^<%# Eval("dataid") %>^<%# Eval("BuildingID") %>" />
                                                            <label for="addrlist_<%# Eval("dataid") %>"><%# Eval("Receiver")%>&nbsp;<%# Eval("Address") %></label>

                                                        </li>
                                                    </ItemTemplate>
                                                </asp:Repeater>
                                            </ul>
                                        </div>

                                    </li>


                                    <li><span class="left_span">定位地址<font color="red"></font>：</span>
                                        <epc:TextBox runat="server" ID="tbaddress" placeholder="请输入地图定位的地址" Width="300px" class="required-entry input_on keyaddress"></epc:TextBox>
                                        <span>
                                            <input
                                                type="button" value="搜索" onclick="showmap()" class="subBtn" id="tbsearchaddress" />
                                        </span></li>
                                    <li id="mapdiv" style="display:;">

                                        <div style="border: 1px solid #EEEEEE; display: inline; float: left; height: 353px; margin: 18px 0 0 13px; width: 550px;"
                                            id="map">
                                            <div style="width: 650px; height: 353px; position: relative; background-color: rgb(229, 227, 223);"
                                                id="map_canvas">
                                            </div>
                                        </div>
                                        <asp:HiddenField runat="server" ID="hdState" />
                                        <div class="clear">
                                        </div>
                                    </li>

                                    <li><span class="left_span">详细地址<font color="red"></font>：</span>
                                        <epc:TextBox runat="server" ID="tbaddressdetail" placeholder="街道 小区 楼号 门牌号" Width="300px" class="required-entry input_on"></epc:TextBox>
                                    </li>


                                    <li style="display: none;"><span class="left_span">送餐份数<font color="red">*</font>：</span>
                                        <epc:TextBox runat="server" ID="tbfoodcount" CanBeNull="必填" Text="1"
                                            Width="90px" class="required-entry input_on"></epc:TextBox>
                                    </li>


                                    <li style="display:none;"><span class="left_span">商品总金额<font color="red">*</font>：</span>
                                        <epc:TextBox runat="server" ID="tbPrice" CanBeNull="必填" Text="0" RequiredFieldType="数据校验" reg="^[-+]?\d+(\.\d+)?$" tip="商品总金额格式错误,请输入数字"
                                            Width="90px" class="required-entry input_on"></epc:TextBox>
                                        元 </li>


                                       <li style="display:none;"><span class="left_span">代收金额<font color="red"></font>：</span>
                                        <epc:TextBox runat="server" ID="tbAdvance" CanBeNull="必填" Text="0" RequiredFieldType="数据校验" reg="^[-+]?\d+(\.\d+)?$" tip="代收金额格式错误,请输入数字"
                                            Width="90px" class="required-entry input_on"></epc:TextBox>
                                        元 </li>



                                    <li><span class="left_span">配送距离<font color="red">*</font>：</span>
                                        <epc:TextBox runat="server" ID="tbcardpay" CanBeNull="必填" Text="0" RequiredFieldType="数据校验" Enabled="false" reg="^[-+]?\d+(\.\d+)?$" tip="请点击 计算配送费 按钮"
                                            Width="90px" class="required-entry input_on"></epc:TextBox>
                                        公里 </li>


                                    <li><span class="left_span">配送费<font color="red">*</font>：</span>
                                        <epc:TextBox runat="server" ID="tbshopdiscountmoney" CanBeNull="必填" Text="" RequiredFieldType="数据校验" reg="^[-+]?\d+(\.\d+)?$" tip="请点击 计算配送费 按钮"
                                            Width="90px" class="required-entry input_on" Enabled="false"></epc:TextBox>
                                        元 

                                <input type="button" value="计算配送费" id="btgetfee" onclick="startcur()" class="subBtn" />

                                        <div class="mynotice">计算配送费后才可以提交订单。</div>

                                    </li>


                                    <li><span class="left_span">票/券<font color="red">*</font>：</span>
                                        <asp:DropDownList runat="server" ID="ddlSystemUserId">
                                            <asp:ListItem Text="否" Value="0"></asp:ListItem>
                                            <asp:ListItem Text="是" Value="1"></asp:ListItem>

                                        </asp:DropDownList>
                                    </li>




                                    <li><span class="left_span">时间<font color="red">*</font>：</span>
                                        <asp:DropDownList
                                            runat="server" ID="ddltime" Width="60px" CssClass="j_seclect">
                                        </asp:DropDownList>
                                    </li>

                                    <li><span class="left_span">备注<font color="red"></font>：</span>
                                        <epc:TextBox runat="server" ID="tbremark" TextMode="MultiLine" Width="300px" class="required-entry input_on"></epc:TextBox>
                                        <div class="clear"></div>
                                        <div style="padding-left: 100px; margin-top: 11px;" class="quick_note_control">
                                            <asp:Repeater runat="server" ID="rptfastremark">
                                                <ItemTemplate>
                                                    <span onclick="settag(this)" mytag="<%#Eval("classname")%>">
                                                        <%# Eval("classname") %></span>
                                                </ItemTemplate>
                                            </asp:Repeater>
                                        </div>
                                        <div class="clear"></div>
                                    </li>

                                    <li style="display:none;"><span class="left_span">其他备注<font color="red"></font>：</span>
                                        <epc:TextBox runat="server" ID="tbcardids" TextMode="MultiLine" Width="300px" class="required-entry input_on"></epc:TextBox>
                                        <span></span>
                                    </li>

                                    <li class="padding90px">
                                        <div style="text-align: center;">
                                            <asp:Button Text="确定(客服调度)" runat="server" ID="btSave" OnClick="btSave_Click" class="userCommonBtn"
                                                OnClientClick="return checkdata();" />


                                            <asp:Button Text="确定(发给附近配送员)" style="display:none" runat="server" ID="btSaveself" OnClick="btSave_Click" class="userCommonBtn" 
                                                OnClientClick="return checkdata();" />


                                        </div>
                                    </li>
                                </ul>
                            </div>

                        </div>
                    </div>

                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
        <foot:foot runat="server" ID="foot" />
    </form>
</body>
</html>
<script type="text/javascript">

    $(document).ready(function () {

        $("#tbSentTime").val(new Date().format("HH:mm"));

        var hfmymoney = parseFloat($("#hfmymoney").val());

        if (hfmymoney <= - 50) {
           
            swal({
                title: "",
                text: "余额不足，请充值后再提交订单",
                type: "warning",
                confirmButtonText: "确定",
                closeOnConfirm: false
            },
                function () {
                    gourl("myindex.aspx");
                });
        }

    })


    function checkdata()
    {
        var flag = j_submitdata("usermima");
        if (!flag)
        {
            return false;
        }


        var add_dataid = $("#add_dataid").val();
        if (add_dataid == 0) {
            var tbaddressdetail = $("#tbaddressdetail").val();
            if (tbaddressdetail.length == 0) {
                alert("请输入请输入街道 小区 楼号 门牌号");
                hideload_super();
                return false;
            }
        }
        showload_super();
        return true;

    }

    //备注标签
    function settag(tag) {
        var or = $("#tbremark").val();
        $("#tbremark").val(or + " " + $(tag).attr("mytag"));
        $(tag).addClass("cull");
    }

    //选择地址
    function setaddress(evt) {

        $('input:radio[name="rbaddress"]').removeAttr("checked");
        evt.checked = true
        var v = evt.value + "";
        var names = v.split('^');
        //<%# Eval("Receiver") %>^<%# Eval("Address")%>^<%# Eval("lat") %>^<%# Eval("lng")%>^<%# Eval("dataid") %>^<%# Eval("BuildingID") %>^<%# Eval("Mobilephone")%>^<%# Eval("Phone") %>

        $("#add_dataid").val(names[4]);
        if (names[4] == "0") {
            return;
        }

        $("#tbname").val(names[0]);
        $("#tbaddress").val(names[1]);
        $("#tbtel").val(names[6]);


        $("#hidLat").val(names[2]);
        $("#hidLng").val(names[3]);


        var _lat = parseFloat(names[2]);
        var _lng = parseFloat(names[3]);

        center = new BMap.Point(_lng, _lat);
        initpoint = new BMap.Point(_lng, _lat);

        map.panTo(center);

        map.clearOverlays();
        var myIcon = new BMap.Icon("../images/marker50.png", new BMap.Size(20, 34), { anchor: new BMap.Size(10, 0) });
        marker = new BMap.Marker(center, { icon: myIcon, title: '当前定位' });
        map.addOverlay(marker);
        marker.enableDragging();
        map.addControl(new BMap.NavigationControl());

        marker.setLabel(mylabel);

        myGeo.getLocation(initpoint, function (rs) {
            var addComp = rs.addressComponents;
            adds = addComp.city + addComp.district + addComp.street + addComp.streetNumber
            mylabel.setContent(adds);
        });

        marker.addEventListener("dragend", function (e) {
            initpoint = e.point;
            setLatLng(initpoint);

            myGeo.getLocation(initpoint, function (rs) {
                var addComp = rs.addressComponents;
                adds = addComp.city + addComp.district + addComp.street + addComp.streetNumber
                mylabel.setContent(adds);
            });
        });

        marker.addEventListener("dragstart", function (e) {
            mylabel.setContent("加载中...");
            adds = "";
        });


    }

</script>
